//
//  HYBookingSection1Cell.m
//  Booking
//
//  Created by Maybe_文仔 on 2018/9/5.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYBookingSection1Cell.h"

@interface HYBookingSection1Cell()<UITextFieldDelegate>
@property (nonatomic, strong) UILabel *cellTitleLab;
@property (nonatomic, strong) UITextField *cellTextField;
@property (nonatomic, strong) UILabel *cellContentLab;
@property (nonatomic, strong) UIButton *cellImg;
@end

@implementation HYBookingSection1Cell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    [self addSubview:self.cellTitleLab];
    [self addSubview:self.cellTextField];
    [self addSubview:self.cellContentLab];
    [self addSubview:self.cellImg];
    
    CGFloat maxWidth = [self.cellTitleLab.text widthForFont:self.cellTitleLab.font] + 5;
    
    [self.cellTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.left.mas_equalTo(self.mas_left).mas_offset(12);
        make.width.mas_equalTo(maxWidth);
    }];
    
    [self.cellImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(self.mas_right).mas_offset(-10);
        make.width.mas_equalTo(25);
    }];
    
    [self.cellTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.left.mas_equalTo(self.cellTitleLab.mas_right).mas_offset(16);
        make.right.mas_equalTo(self.mas_right).mas_offset(-10);
    }];
    
    [self.cellContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.left.mas_equalTo(self.cellTitleLab.mas_right).mas_offset(16);
        make.right.mas_equalTo(self.cellImg.mas_left).mas_offset(-18);
    }];
}

-(void)setDataWithTitle:(NSString *)title withContent:(NSString *)content withImage:(NSString *)imageName{
    self.cellTitleLab.text = title;
    self.cellContentLab.text = content;
    [self.cellImg setImage:[UIImage imageNamed:imageName] forState:(UIControlStateNormal)];
    if (imageName.length == 0) {
        self.cellContentLab.hidden = YES;
        self.cellTextField.hidden = NO;
    }
    else{
        self.cellTextField.hidden = YES;
        self.cellContentLab.hidden = NO;
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.inputTextChangeBlock) {
        self.inputTextChangeBlock(textField.text);
    }
}

#pragma mark -- 懒加载

-(UILabel *)cellTitleLab{
    if (!_cellTitleLab) {
        _cellTitleLab = [[UILabel alloc]init];
        _cellTitleLab.textColor = [UIColor blackColor];
        _cellTitleLab.font = KFitFont(15);
        _cellTitleLab.text = NSLocalizedString(@"internalAttendees", nil);
    }
    return _cellTitleLab;
}

-(UITextField *)cellTextField{
    if (!_cellTextField) {
        _cellTextField = [[UITextField alloc]init];
        _cellTextField.textColor = RGBColor(178, 178, 178);
        _cellTextField.placeholder = NSLocalizedString(@"meetingNamePlaceholder", nil);
        _cellTextField.delegate = self;
        _cellTextField.font = KFitFont(15);
    }
    return _cellTextField;
}

-(UILabel *)cellContentLab{
    if (!_cellContentLab) {
        _cellContentLab = [[UILabel alloc]init];
        _cellContentLab.textColor = RGBColor(178, 178, 178);
        _cellContentLab.font = KFitFont(15);
    }
    return _cellContentLab;
}

-(UIButton *)cellImg{
    if (!_cellImg) {
        _cellImg = [[UIButton alloc]init];
        _cellImg.userInteractionEnabled = NO;
    }
    return _cellImg;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:NO];

    // Configure the view for the selected state
}

@end
